package com.scuec.demo.mapper;

import com.scuec.demo.entity.StudentInfo;
import com.scuec.demo.vo.ViewStudentInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

@Mapper
//http://localhost:8080/stu/list
public interface StudentMapper {

    @Select("select stu.*,c.classname FROM world.student_info stu \n" +
            "join classinfo c \n" +
            "on stu.clsid = c.clsid order by stu.stuid desc")
    List<ViewStudentInfo> findStudentInfo();

    @Select("select * from student_info")
    public List<StudentInfo> getStudentInfo();

    @Select("select * from student_info where stuid=#{id}")
    StudentInfo getStudentInfoById(Integer id);

    @Delete("delete from student_info where stuid=#{id}")
    public int  deleteStudentInfoById(Integer id);

    @Insert("insert into student_info (stu_no,stu_name,stu_sex,stu_birthday,stu_education,stu_interest,my_color,create_date,clsid) \n" +
            "values(#{stu_no},#{stu_name},#{stu_sex},#{stu_birthday},#{stu_education}, #{stu_interest},#{my_color},sysdate(),#{clsid})")
    int insertStudentInfo(StudentInfo studentInfo);

    @Update("update student_info set stu_name=#{stu_name}, stu_sex=#{stu_sex}, stu_phone=#{stu_phone}, stu_address=#{stu_address}, stu_birthday=#{stu_birthday}, \n" +
            "stu_email=#{stu_email}, stu_education=#{stu_education}, stu_interest=#{stu_interest}, my_color=#{my_color}, lucky_number=#{lucky_number}, re_mark=#{re_mark} \n" +
            "where stuid=#{stuid}")
    int updateStudentInfo(StudentInfo studentInfo);
}


